package main

import (
	"fmt"
	"reflect"
)

/**
四种变量的声明方式
*/

func main() {
	// 1 声明类型，未赋初始值
	var a int
	fmt.Println("a =", a)
	fmt.Printf("type of a is %T", a)
	fmt.Println()

	// 2 声明类型，赋初值
	var b float32 = 100.891
	fmt.Println("b =", b)

	var bb string = "abcd"
	fmt.Println("bb =", bb)
	fmt.Printf("bb = %s, type of bb is %T", bb, bb)
	fmt.Println()

	// 3 不声明类型，赋初值，自动推断
	var c = 0.23
	fmt.Println("c =", c)
	fmt.Println("type of c is", reflect.TypeOf(c))

	// 4 省去var关键字，直接自动匹配
	e := 100
	fmt.Println("e =", e)
	fmt.Printf("type of e is %T", e)
	fmt.Println()

	// ====================

	// 声明多个变量
	var a1, b1 float32 = 100.2, 11
	fmt.Println("a1 =", a1, "b1 =", b1, "type of a1 is", reflect.TypeOf(a1), "type of b1 is", reflect.TypeOf(b1))

	// 多行
	var (
		vv int  = 100
		jj bool = false
	)
	fmt.Println("vv =", vv, "jj =", jj)

}
